﻿
if (typeof (jQuery) == "undefined") {
    throw "jQuery 未引入 , 请引入jQuery后刷新页面";
}

var feditor_server_path = "/Admin/ashx/feditor.ashx";
var feditor_base_path = "/Admin/assets/feditor/js/";

document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/codemirror/codemirror.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/codemirror/xml.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "froala_editor.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/align.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/char_counter.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/code_beautifier.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/code_view.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/colors.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/draggable.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/emoticons.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/entities.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/file.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/font_size.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/font_family.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/fullscreen.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/image.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/image_manager.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/line_breaker.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/inline_style.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/link.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/lists.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/paragraph_format.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/paragraph_style.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/quick_insert.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/quote.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/table.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/save.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/url.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/video.min.js\"></script>");

//document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/help.min.js\"></script>");
//document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/print.min.js\"></script>");
//document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "third_party/image_tui.min.js\"></script>");

document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/special_characters.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "plugins/word_paste.min.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"" + feditor_base_path + "languages/zh_cn.js\"></script>");


//初始化常规编辑器-批量-Iframe模式- 仅在后台初始化编辑器使用
function InitFeditorIFrameFull(feditObj) {
    if (arguments.length == 0) {
        feditObj = $("[data-fedit='true']");
    }
    $.each(feditObj, function (i, e) {
        $(e).on('froalaEditor.initialized', function (f, editor) {
            var v = window["feditor_content_" + $(e).attr("field")];
            if (v === undefined) {
                v = $("#" + "feditor_default_" + $(e).attr("field")).val();
            }
            $(e).froalaEditor("html.set", v);
            //console.log($(this).css("display", "none"));
            //$(this).css("visibility", "visible").css("overflow", "");
        });
        $(e).froalaEditor({
            key: '',
            language: 'zh_cn',
            height: 500,
            toolbarStickyOffset: 45,
            charCounterCount: false,
            tabSpaces: 4,
            iframe: true,
            iframeStyleFiles: ['/SysRes/dist/css/ueditor_iframe.css', '/Admin/assets/feditor/css/loadfeditor.css'],
            // disable quick insert
            quickInsertTags: [],
            // toolbar buttons
            toolbarButtons: ['html', 'bold', 'italic', 'underline', 'strikeThrough', '|', 'paragraphFormat', 'fontFamily', 'fontSize', 'color', '|', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', 'clearFormatting', '-', 'insertLink', 'insertFile', 'insertImage', 'insertVideo', 'embedly', 'insertTable', '|', 'insertHR', 'selectAll', 'clearFormatting', '|', 'spellChecker', '|', 'undo', 'redo', '|', 'fullscreen'],

            fontFamily: {
                'Microsoft Yahei': '微软雅黑',
                'Arial,Helvetica,sans-serif': 'Arial',
                'Georgia,serif': 'Georgia',
                'Impact,Charcoal,sans-serif': 'Impact',
                'Tahoma,Geneva,sans-serif': 'Tahoma',
                "'Times New Roman',Times,serif": 'Times New Roman',
                'Verdana,Geneva,sans-serif': 'Verdana'
            },

            // upload file
            fileUploadParams: { token: "edit" },
            fileUploadURL: feditor_server_path + '?action=singleuploadfile',
            fileUploadMethod: 'post',
            fileMaxSize: 50 * 1024 * 1024, //50M
            fileAllowedTypes: ['*'],
            fileUseSelectedText: true,

            // upload image
            imageCORSProxy: '',
            imageUploadParams: { token: "edit" },
            imageUploadURL: feditor_server_path + '?action=singleuploadimage',
            imageUploadMethod: 'post',
            imageMaxSize: 10 * 1024 * 1024, //10M
            imageAllowedTypes: ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'svg+xml'],
            //delete image
            imageManagerDeleteMethod: 'post',
            imageManagerDeleteParams: { token: "edit" },
            imageManagerDeleteURL: feditor_server_path + '?action=deleteimage',
            //load image
            imageManagerLoadMethod: 'post',
            imageManagerLoadParams: { token: "edit" },
            imageManagerScrollOffset: 20,
            imageManagerPageSize: 20,
            imageManagerLoadURL: feditor_server_path + '?action=loadimagelist',

            // upload video
            videoUploadParams: { token: "edit" },
            videoUploadURL: feditor_server_path + '?action=singleuploadvideo',
            videoUploadMethod: 'post',
            videoMaxSize: 100 * 1024 * 1024, //100M
            videoAllowedTypes: ['mp4'],

        }).on('froalaEditor.file.error', function (e, editor, error, response) {
            // handle errors
            alert("上传出错了 , 请稍后重试");
        }).on('froalaEditor.image.error', function (e, editor, error, response) {
            // handle errors
            alert("上传出错了 , 请稍后重试");
        }).on('froalaEditor.video.error', function (e, editor, error, response) {
            // handle errors
            alert("上传出错了 , 请稍后重试");
        });
        
    });
}


//初始化常规编辑器-批量
function InitFeditorFull(feditObj){
    if (arguments.length == 0) {
        feditObj = $("[data-fedit='true']");
    }
    $.each(feditObj, function (i, e) {
        $(e).froalaEditor({
            key: '',
            language: 'zh_cn',
            height: 500,
            charCounterCount: false,
            iframeStyleFiles: ['/SysRes/dist/css/ueditor_iframe.css','/Admin/assets/feditor/css/loadfeditor.css'],
            // disable quick insert
            quickInsertTags: [],
            // toolbar buttons
            toolbarButtons: ['html', 'bold', 'italic', 'underline', 'strikeThrough', '|', 'paragraphFormat', 'fontFamily', 'fontSize', 'color', '|', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', 'clearFormatting', '-', 'insertLink', 'insertFile', 'insertImage', 'insertVideo', 'embedly', 'insertTable', '|', 'insertHR', 'selectAll', 'clearFormatting', '|', 'spellChecker', '|', 'undo', 'redo', '|', 'fullscreen'],

            fontFamily: {
                'Microsoft Yahei': '微软雅黑',
                'Arial,Helvetica,sans-serif': 'Arial',
                'Georgia,serif': 'Georgia',
                'Impact,Charcoal,sans-serif': 'Impact',
                'Tahoma,Geneva,sans-serif': 'Tahoma',
                "'Times New Roman',Times,serif": 'Times New Roman',
                'Verdana,Geneva,sans-serif': 'Verdana'
            },

            // upload file
            fileUploadParams: { token: "edit" },
            fileUploadURL: feditor_server_path + '?action=singleuploadfile',
            fileUploadMethod: 'post',
            fileMaxSize: 50 * 1024 * 1024, //50M
            fileAllowedTypes: ['*'],
            fileUseSelectedText: true,

            // upload image
            imageCORSProxy: '',
            imageUploadParams: { token: "edit" },
            imageUploadURL: feditor_server_path + '?action=singleuploadimage',
            imageUploadMethod: 'post',
            imageMaxSize: 10 * 1024 * 1024, //10M
            imageAllowedTypes: ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'svg+xml'],
            //delete image
            imageManagerDeleteMethod: 'post',
            imageManagerDeleteParams: { token: "edit" },
            imageManagerDeleteURL: feditor_server_path + '?action=deleteimage',
            //load image
            imageManagerLoadMethod: 'post',
            imageManagerLoadParams: { token: "edit" },
            imageManagerScrollOffset: 20,
            imageManagerPageSize: 20,
            imageManagerLoadURL: feditor_server_path + '?action=loadimagelist',

            // upload video
            videoUploadParams: { token: "edit" },
            videoUploadURL: feditor_server_path + '?action=singleuploadvideo',
            videoUploadMethod: 'post',
            videoMaxSize: 100 * 1024 * 1024, //100M
            videoAllowedTypes: ['mp4'],

        }).on('froalaEditor.initialized', function (e, editor) {
            // Do something here.
        }).on('froalaEditor.file.error', function (e, editor, error, response) {
            // handle errors
        }).on('froalaEditor.image.error', function (e, editor, error, response) {
            // handle errors
        }).on('froalaEditor.video.error', function (e, editor, error, response) {
            // handle errors
            alert(error.message);
        });
    });
}

//初始化Inline编辑器-批量
function InitFeditorInline(feditObj) {
    if (arguments.length == 0) {
        feditObj = $("[data-fedit='true']");
    }
    $.each(feditObj, function (i, e) {
        $(e).froalaEditor({
            language: 'zh_cn',
            toolbarInline: true,
            charCounterCount: false,
            //alwaysVisible: true,
            //quickInsertTags: [],
            quickInsertButtons: ['image', 'ul', 'ol', 'hr'],
            toolbarButtons: ['bold', 'italic', 'underline', 'strikeThrough', 'color', 'fontSize', 'fontFamily', '-', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'indent', 'outdent', 'clearFormatting', '-', 'insertImage', 'insertLink', 'insertFile', 'insertVideo', 'undo', 'redo', 'html'],
            toolbarButtonsXS: null,
            toolbarButtonsSM: null,
            toolbarButtonsMD: null,

            fontFamily: {
                'Microsoft Yahei': '微软雅黑',
                'Arial,Helvetica,sans-serif': 'Arial',
                'Georgia,serif': 'Georgia',
                'Impact,Charcoal,sans-serif': 'Impact',
                'Tahoma,Geneva,sans-serif': 'Tahoma',
                "'Times New Roman',Times,serif": 'Times New Roman',
                'Verdana,Geneva,sans-serif': 'Verdana'
            },

            // upload file
            fileUploadParams: { token: "edit" },
            fileUploadURL: feditor_server_path + '?action=singleuploadfile',
            fileUploadMethod: 'post',
            fileMaxSize: 50 * 1024 * 1024, //50M
            fileAllowedTypes: ['pdf', 'apk', 'ipk', 'rar', 'zip', '7z', 'doc', 'docx', 'ppt', 'xls', 'xlsx', 'wps', 'mp3', 'mp4', 'txt'],
            fileUseSelectedText: true,

            // upload image
            imageCORSProxy: '',
            imageUploadParams: { token: "edit" },
            imageUploadURL: feditor_server_path + '?action=singleuploadimage',
            imageUploadMethod: 'post',
            imageMaxSize: 10 * 1024 * 1024, //10M
            imageAllowedTypes: ['jpeg', 'jpg', 'png', 'gif', 'bmp'],
            //delete image
            imageManagerDeleteMethod: 'post',
            imageManagerDeleteParams: { token: "edit" },
            imageManagerDeleteURL: feditor_server_path + '?action=deleteimage',
            //load image
            imageManagerLoadMethod: 'post',
            imageManagerLoadParams: { token: "edit" },
            imageManagerScrollOffset: 20,
            imageManagerPageSize: 20,
            imageManagerLoadURL: feditor_server_path + '?action=loadimagelist',

            // upload video
            videoUploadParams: { token: "edit" },
            videoUploadURL: feditor_server_path + '?action=singleuploadvideo',
            videoUploadMethod: 'post',
            videoMaxSize: 100 * 1024 * 1024, //100M
            videoAllowedTypes: ['mp4'],

        }).on('froalaEditor.initializationDelayed', function (e, editor) {
            console.log("123");
        }).on('froalaEditor.file.error', function (e, editor, error, response) {
            // handle errors
        }).on('froalaEditor.image.error', function (e, editor, error, response) {
            // handle errors
        }).on('froalaEditor.video.error', function (e, editor, error, response) {
            // handle errors
            alert(error.message);
        });
    });
}

//InitFeditorInline();